<?php


namespace App\Http\Controllers\user;


use App\Engine\BaseController;
use App\Engine\TokenService;
use App\Http\Validate\YuyueValidate;
use App\Models\Yuyue as YuyueModel;
use function app\Utils\go;

class Yuyue extends BaseController
{

    /**
     * 添加预约记录
     */
    public function insert()
    {

        $this->validate($this->request,YuyueValidate::$rule,YuyueValidate::$message);

        $this->post['uid']=TokenService::getCurrentUid();

        $res=YuyueModel::create($this->post);
        return go($res);
    }
    
    /**
     * 获取预约记录
     * */
    public function get()
    {
        $uid=TokenService::getCurrentUid();
        $res=YuyueModel::where('uid',$uid)->orderBy('id','desc')->get();
        return go($res);
    }
    
    /**
     * 取消预约
     * */
    public function cancel()
    {
        $res=YuyueModel::where('id',$this->get['id'])->update(['state'=>2]);
        return go($res);
    }
}
